package com.example.administrator.myapplication;

import android.app.AlertDialog;
import android.app.Notification;
import android.app.NotificationManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
import android.util.Log;

import cn.jpush.android.api.JPushInterface;

public class MyReciver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        Bundle bundle=intent.getExtras();
        if (JPushInterface.ACTION_NOTIFICATION_RECEIVED.equals(intent.getAction())){
        }else if (JPushInterface.ACTION_MESSAGE_RECEIVED.equals(intent.getAction())){
            String message=bundle.getString(JPushInterface.EXTRA_MESSAGE);

                sendNotification(message,context);



        }
        }
    private void sendNotification(String message,Context mcontext){
        NotificationManager manager= (NotificationManager)mcontext.getSystemService(Context.NOTIFICATION_SERVICE);
        Notification.Builder builder=new Notification.Builder(mcontext);
        builder.setContentTitle("12312")
        .setContentText(message)
        .setWhen(System.currentTimeMillis())
        .setSmallIcon(R.mipmap.ic_launcher)
        .setDefaults(Notification.DEFAULT_ALL)
        .setTicker("手机消息提醒");
        Notification notification=builder.build();
        manager.notify(1,notification);
    }

}
